<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p{
            background-color: greenyellow;
        }
    </style>
</head>
<body>
    <div class = "divClass">
        <p>测试内容1</p>
        <p>测试内容2</p>
        <p>测试内容3</p>
    </div>

    <script>
        var div1 = document.querySelector('div');
        /*target属性用于返回一个事件触发对象*/
        div1.onclick = function(event){
            if(event.target.className != 'divClass'){
                alert('测试内容已被点击');
            }
        }
    </script>
</body>
</html>